package org.thirdHero.wx.web;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMethod;
import org.thirdHero.core.util.ResponseUtil;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.thirdHero.wx.domain.WxUserOpenId;
import org.thirdHero.wx.service.UserInfoService;

import java.util.HashMap;
import java.util.Map;

@RestController
@RequestMapping("/buyer/index")
public class WxIndexController {
    private final Log logger = LogFactory.getLog(WxIndexController.class);

    @Value("${wx.app-id}")
    private String appId;

    @Value("${wx.app-secret}")
    private String appSecret;

    @Autowired
    private UserInfoService userInfoService;

    @RequestMapping("/index")
    public Object index(){
        return ResponseUtil.ok("hello world, this is wx service");
    }

    @RequestMapping(value = "/login", method = RequestMethod.POST)
    public Object getOpenId(@RequestBody Map<String, Object> reqMap){
        try{
            String code = reqMap.get("code").toString();
            WxUserOpenId wxUserOpenId = userInfoService.getWxUserOpenId(appId, appSecret, code);

        }catch (Exception e){

        }

        return ResponseUtil.ok();
    }

}